<template>
  <div class="page">
    <avue-crud
      :data="data"
      :option="option"
      @refresh-change="refreshChange"
      @row-save="rowSave"
      @row-update="rowUpdate"
      @row-del="rowDel"
    ></avue-crud>
  </div>
</template>

<script>
import config from '@/config.js'

export default {
  data() {
    return {
      data: [],
      option: {
        column: [
          {
            label: `账号`,
            prop: `user`,
          },
          {
            label: ` 密码`,
            prop: `pass`,
          },
        ],
      },
    }
  },
  async created() {
    this.refreshChange()
  },
  methods: {
    async refreshChange() {
      this.data = await this.$http.instance.get(`/user`)
    },
    async rowSave(form, done, loading) {
      await this.$http.instance.post(`/user`, form)
      done(form)
    },
    async rowDel(form, index, done) {
      await this.$http.instance.delete(`/user/${form.id}`)
      done(form)
    },
    async rowUpdate(form, index, done, loading) {
      await this.$http.instance.patch(`/user/${form.id}`, form)
      done(form)
    },
  },
}
</script>
